package main;

import mongodb.OutputData;
import moveMysql.OutputMysql;
import ossOutput.FileOutput;

import java.util.LinkedList;
import java.util.List;

import static configure.OutputConfig.CASE_IDS;
import static configure.OutputConfig.readOutputConfig;

public class Output {
    public static void main(String[] args) {
        System.out.println(args.length);
        try {
            readOutputConfig();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(CASE_IDS.length==0){
            outputAll();
            System.out.println("all");
        }else{
            LinkedList<Long> caseId = new LinkedList<>();
            for (String id : CASE_IDS){
                caseId.add(Long.parseLong(id));
                System.out.println(id);
            }
            outputByCase(caseId);
        }

        //1467,1468,1469,1470,1471
        //
    }

    public static void outputAll() {
        try {

            //导出mongo数据
            System.out.println("正在导出mongodb的数据");
            OutputData.mongoDataOut();
            System.out.println("mongodb数据导出完成");
            //导出MySQL数据
            System.out.println("正在导出MySQL的数据");
            OutputMysql.mysqlDataOut();
            System.out.println("MySQL数据导出完成");
            //导出文件
            System.out.println("正在导出文件");
            FileOutput.fileOut();
            System.out.println("文件导出完成");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void outputByCase(List<Long> caseId) {
        try {
            //导出MySQL数据
            System.out.println("正在导出MySQL的数据");
            LinkedList<Long> targetIds = OutputMysql.mysqlDataOut(caseId);
            System.out.println("MySQL数据导出完成");
            //导出mongo数据
            System.out.println("正在导出mongodb的数据");
            OutputData.mongoDataOut(caseId, targetIds);
            System.out.println("mongodb数据导出完成");

            //导出文件
            System.out.println("正在导出文件");
            FileOutput.fileOut(caseId, targetIds);
            System.out.println("文件导出完成");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
